#import "ForcesTableView.h"

@implementation ForcesTableView
- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset {
	NSRect imageRect = NSMakeRect(0,0,32,32);
	NSRect dragRect = NSMakeRect(4,4,24,24);
	NSImage * dragImage = [[NSImage alloc] initWithSize:imageRect.size];
	[dragImage lockFocus];
	NSBezierPath * bp = [NSBezierPath bezierPathWithOvalInRect:dragRect];
	int playerIndex = [[self dataSource] playerNumberForTableView:self rowIndex:[dragRows firstIndex]];
	[[[self dataSource] colorForPlayerIndex:playerIndex] set];
	[bp fill];
	[[NSColor blackColor] set];
	[bp setLineWidth:2.0];
	[bp stroke];
	
	NSAttributedString * string = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%i", playerIndex+1] attributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSColor blackColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize:20.0], NSFontAttributeName, NULL]];
	
	NSRect stringBounds = [string boundingRectWithSize:NSMakeSize(20,20) options:NSStringDrawingOneShot];
	
	NSPoint centerPoint = NSMakePoint( 16.0 - (stringBounds.size.width / 2.0), 16.0 - (stringBounds.size.height / 2.0) );
	[string drawAtPoint: centerPoint ];
	//NSLog(NSStringFromRect( stringBounds ));
	//NSLog(NSStringFromPoint( centerPoint ));

	dragImageOffset->x -= 10;
	dragImageOffset->y += 10;

	[dragImage unlockFocus];
	return dragImage;
}
@end
